package cn.edu.hziee;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "UpdateServlet",urlPatterns = "/UpdateServlet" )
public class UpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));
        HttpSession session = request.getSession();
        List<Grade> card = (List<Grade>) session.getAttribute("card");
        Grade grade = new Grade();
a:        for(int i=0;i<card.size();i++){
            if(id==card.get(i).getId()){
                grade = card.get(i);
                card.get(i).setId(i);
                break a;
            }
        }
        session.setAttribute("update", grade);
        session.setAttribute("id", id);
        response.sendRedirect("/Traversal/update.jsp");
    }
}
